﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Ovvio.Web.Areas.Admin.Models.ProductModel>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Products
	
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 
     <% Html.Telerik().Grid(Model)
        .Name("ProductsGrid")
        .DataKeys(keys => { keys.Add(p => p.Id).RouteKey("Id"); })
        .ToolBar(toolbar => toolbar.Template(() =>
            { %>
                <table style="width: 100%" align="center">
                <tr style="height:15px">
                    <td>
                        <%= Html.Label("Product") %>
                        <%= Html.TextBox("TextBoxProductName", ViewData["ProductName"]) %>
                        <a onclick="onSearchClick();" class= "t-button t-button-icontext t-grid-add" >Search</a>
                    </td>
                    <td align="right" >
                        <%= Html.Telerik().DropDownList()
                            .Name("CategoryFilter")
                            .BindTo((SelectList)ViewData["Categories"] )
                            .HtmlAttributes(new {style="text-align:left", id="categoryId"})
                            .ClientEvents(events => events.OnChange("onCategoryChange")) 
                        %>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <%= Html.ActionLink("New Product Entry", "Create", null, new { @class = "t-button t-button-icontext t-grid-add" })%>
                    </td>
                </tr>
                </table>
               <%
            }))
        .DataBinding(dataBinding => dataBinding.Server()
            .Delete("Delete","Products"))
        .Sortable()
        .Scrollable(scroll => scroll.Height(250))
        .Columns(columns =>
        {
            columns.Template(o => 
            { %> 
                <img  src="<%= Url.Action("Thumb/" + o.Id.ToString()) %>" alt="<%= o.Name %>" width=50 height=50/>
            <% }).Width(60);
            columns.Template(o => @Html.ActionLink(o.Name, "Edit", "Products", new { id = o.Id }, null)).Title("Name").Width(150);
            columns.Bound(o => o.Details).Width(300);
            columns.Bound(o => o.Price).Format("{0:c}").Width(50);
            columns.Bound(o => o.IsPublished).Width(50);
            columns.Bound(o => o.IsOnStock).Width(50);
            columns.Command(command => command.Delete().ButtonType(GridButtonType.BareImage)).Width(30);
        })
        .Render();
    %>
    
   <script type="text/javascript">
       function onCategoryChange(e) {
            var actionUrl = "<%=Url.Action("List", "Products", new { area = "Admin", category = "categoryValue", productName = "productNameValue" }) %>";
            var productName = $("#TextBoxProductName").val();
            var category = '';
            if (e.value !=  "Select Category")
                category = e.value;
            window.location.href = actionUrl.replace('categoryValue',category).replace('productNameValue',productName).replace(' ','%20');
       }
       function onSearchClick() {
            var actionUrl = "<%=Url.Action("List", "Products", new { area = "Admin", productName = "productNameValue" }) %>";
            var productName = $("#TextBoxProductName").val();
            window.location.href = actionUrl.replace('productNameValue',productName).replace(' ','%20');
       }
    </script>
    
    <%--<table style="width: 100%" align="center">
    <tr>
        <td>
            <%= Html.TextBox("TextSearch") %>
            <%= Html.ActionLink("Search", "Search") %>
        </td>
        <td align="right">
            <%= Html.Label("Select By Category") %>
             <%= Html.DropDownList("Filter", new List<SelectListItem>() { new SelectListItem() { Text="Featured Products"}}) %>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <%= Html.ActionLink("New Product Entry", "Create", null, new { @class = "t-button t-button-icontext t-grid-add" })%>
        </td>
    </tr>
    </table>
    
    <table style="width: 100%" align="center">
        <tr>
            <th>
               
            </th>
            <th>
                Name
            </th>
            <th>
                Details
            </th>
            <th>
                Price
            </th>
            <th>
                On-Stock
            </th>
            <th>
                Published
            </th>
        </tr>

    <% foreach (var item in Model) { %>
    
        <tr>
            
            <td>
                <img src="<%= Url.Action("Thumb/" + item.Id.ToString()) %>" alt="<%= item.Name %>" width=50 height=50/>
            </td>
            <td>
                <%= Html.Encode(item.Name) %>
            </td>
            <td>
                <%= Html.Encode(item.Details) %>
            </td>
            <td>
                <%= Html.Encode(String.Format("{0:F}", item.Price)) %>
            </td>   
            <td>
                <%= Html.CheckBox("On-Stock",item.IsOnStock, new { @disabled = true })%>
            </td>
            <td>
                <%= Html.CheckBox("Published", item.IsPublished, new { @disabled = true })%>
            </td>
            <td><br />
             <%= Html.ActionLink("Details", "Details", new { id = item.Id /* id=item.PrimaryKey */ })%>
                <%= Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "t-icon t-edit" })%> <br />
                <%= Html.ActionLink("Delete", "Delete", new { id = item.Id /* id=item.PrimaryKey */ })%> 
            </td>
        </tr>
    
    <% } %>

    </table>
--%>
    

</asp:Content>

